package br.com.mundodaprata.store.model;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

@Entity
@Table
public class Street extends AbstractEntity {

	private static final long serialVersionUID = 1L;

	@Id
	@Column
	private Long code;

	@Column(nullable = false)
	private String state;

	@ManyToOne
	@JoinColumn(name = "city")
	private City city;

	@ManyToOne
	@JoinColumn(name = "neighborhood")
	private Neighborhood neighborhood;

	@Column(nullable = false)
	private String name;

	@Column(name = "zip_code")
	private String zipCode;

	@Column
	private String type;

	public Long getCode() {
		return code;
	}

	public void setCode(Long code) {
		this.code = code;
	}

	public String getState() {
		return state;
	}

	public void setState(String state) {
		this.state = state;
	}

	public City getCity() {
		return city;
	}

	public void setCity(City city) {
		this.city = city;
	}

	public Neighborhood getNeighborhood() {
		return neighborhood;
	}

	public void setNeighborhood(Neighborhood neighborhood) {
		this.neighborhood = neighborhood;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getZipCode() {
		return zipCode;
	}

	public void setZipCode(String zipCode) {
		if(zipCode.matches("[0-9]{5}-[0-9]{3}")){
			zipCode = zipCode.replaceAll("-", "");
		}
		
		
		this.zipCode = zipCode;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}
}